﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TestMySqlConnetPoll;
using DevExpress.Skins;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;

namespace View.Table
{
    /// <summary>
    /// 实时开关量表
    /// </summary>
    public partial class SwitchForm : DevExpress.XtraEditors.XtraForm
    {
        List<kglstruct> source = new List<kglstruct>();
        //DataTable dtSource = c_RealTimeValue.KglRealTimeTable.Copy();
        public SwitchForm()
        {
            InitializeComponent();
            gridView1.CustomDrawCell += gridView1_CustomDrawCell;
            source = c_RealTimeValue.kglRealTimeList;
            this.DevDataGrid.DataSource = source;
            //col_type.Group();
            //barCheck_Type.Checked = true;
            this.gridView1.BestFitColumns();            
        }

        void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            string val = gridView1.GetRowCellValue(e.RowHandle, "状态") as string;
            GridCellInfo cell = e.Cell as GridCellInfo;
            if (cell.Column.Name == "状态")
                if (c_RealTimeValue.kglRealTimeList[e.RowHandle].BHflag== "1")
                    cell.Appearance.ForeColor = CommonColors.GetCriticalColor(DevExpress.LookAndFeel.UserLookAndFeel.Default);
        }

        /// <summary>
        /// 实时绑定开关量
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KGL_Timer_Tick(object sender, EventArgs e)
        {
            //this.DevDataGrid.MainView.BeginDataUpdate();
            // c_RealTimeValue.RefreshRealTimeData();
            //dtSource = c_RealTimeValue.KglRealTimeTable.Copy();
            //this.DevDataGrid.DataSource = source;
            //this.DevDataGrid.MainView.EndDataUpdate();
        }

        /// <summary>
        /// 添加行号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void View_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();
            }
        }

        private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            //string val = gridView1.GetRowCellValue(e.RowHandle, "状态") as string;
           
            //if (val == "↓")
            //    e.Appearance.ForeColor = CommonColors.GetCriticalColor(DevExpress.LookAndFeel.UserLookAndFeel.Default);
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void barCheck_Csm_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barCheck_Csm.Checked == false)
            {
                col_Csm.UnGroup();
            }
            else
            {
                col_Csm.Group();
                barCheck_Type.Checked = false;
                barCheck_DevName.Checked = false;
            }
        }

        private void barCheck_DevName_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barCheck_DevName.Checked == false)
            {
                col_DevName.UnGroup();
            }
            else
            {
                col_DevName.Group();
                barCheck_Csm.Checked = false;
                barCheck_Type.Checked = false;
            }
        }

        private void barCheck_Type_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if(barCheck_Type.Checked == false)
            {
                col_type.UnGroup();
            }
            else
            {
                col_type.Group();
                barCheck_DevName.Checked = false;
                barCheck_Csm.Checked = false;
            }
        }

        private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
        {
            GridGroupRowInfo GridGroupRowInfo = e.Info as GridGroupRowInfo;
            string s = GridGroupRowInfo.GroupValueText;
            string gtext = s;
            ///统计分组个数.
        }
    }
}